
define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function () {
            var that = this;
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            Fast.api.ajax({
                url: window.Config.moduleurl + "/csmwj/xp_paper_dashboard/indexChartDataset",
                type: "get",
            }, function (data, ret) {
                var option = that._option(data.option.applydate_array, data.option.series_object_array, data.option.series_data_array_array);
                myChart.setOption(option);
                return false;
            }, function (data, ret) {
                return false;
            });
            // var applydate_array = ['2022-06-12', '2022-06-13', '2022-06-14', '2022-06-15', '2022-06-16'];
            // var series_key_array = ['上海分公司大楼1','上海分公司大楼2'];
            // var series_data_array = {
            //     totalhours:[[0, 0, 1, 0, 0],[0, 0, 1, 0, 0]]
            //     totaluser:[[3, 0, 0, 0, 2],[3, 0, 0, 0, 2]]
            // };
            // var option = that._option(applydate_array, series_key_array,series_data_array);
            // myChart.setOption(option);
            $(window).resize(function () {
                myChart.resize();
            });

            $(document).on("click", ".btn-refresh", function () {
                window.location.reload();
            });

        },
        _option: function (fields, series_object_array, series_data_array_array) {
            var series_data = [];
            var series_data_array = null;
            series_data_array = series_data_array_array['val1'];
            for (var index in series_data_array) {
                series_data.push({
                    type: 'bar',
                    name: series_object_array[index]+"填写工单数",
                    data: series_data_array[index]
                });
            }
            series_data_array = series_data_array_array['val2'];
            for (var index in series_data_array) {
                series_data.push({
                    type: 'line',
                    name: series_object_array[index]+"填写工单人数",
                    data: series_data_array[index]
                });
            }

            var option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        dataView: {
                            show: true,
                            readOnly: false
                        },
                        magicType: {
                            show: true,
                            type: ['line', 'bar']
                        },
                        restore: {
                            show: true
                        },
                        saveAsImage: {
                            show: true
                        }
                    }
                },
                legend: {
                    orient: 'horizontal',
                },
                xAxis: {
                    data: fields
                },
                yAxis: {},
                series: series_data
            };
            return option;

        }
    };

    return Controller;
});
